#!/usr/bin/python
# -*- coding=utf-8 -*-
# author : fzk
# date: 20220218
# version: 0.1

# 1. 导入Flask类；

from flask import Flask,jsonify,request
from flask_cors import CORS
from SearchJsonG import DoJson

import json
# 2. 实例化一个Flask对象；

#     __name__是模块的名称或者包的名称

#     作用: 根据这个参数确定flask应用的路径， 从而快速查找模板和html文件的默认路径；

#     模块就是python文件; 包就是目录(跟普通目录多加一个__init__.py);

#

app = Flask(__name__)
CORS(app, supports_credentials=True)
app.config['JSON_AS_ASCII'] = False
# 3-1.基本路由:通过路由绑定一个视图函数

#   @app.route('/'): 告诉Flask哪个URL才能出发对应的函数， 又称为路由;

#   对应定义了一个视图函数， 也就是返回给用户浏览器显示的内容;


@app.route('/')
def index():
    return "hello world"


meun1 = {'meun': [{ "date": '0', "label": "日期", "width": "180px", "display": True },
                        {"date": '1', "label": "姓名", "width": "180px", "display": True},
                        {"date": '2', "label": "地址", "width": "260px", "display": True}]}


clo = {"col":{"columnList": [{"prop": "pd01ad01","label": "pd01ad01","show": True},{"prop": "pd01er03","label": "pd01er03","show": True},{"prop": "pd01ed01","label": "pd01ed01","show": True}],"testDatas": [{"pd01ad01": {"content": "D1","path": ["accountInfos",0,"accountBasic","pd01ad01"],"show": True},"pd01er03": {"content": "2022-02","path": ["accountInfos",1,"latest5year","latest5yearDetails",0,"pd01er03"],"show": True},"pd01ed01": {"content": "B","path": ["accountInfos",1,"latest5year","latest5yearDetails",0,"pd01ed01"],"show": True}},{"pd01ad01": {"content": "R4","path": ["accountInfos",1,"accountBasic","pd01ad01"],"show": True},"pd01er03": {"content": "2022-01","path": ["accountInfos",1,"latest5year","latest5yearDetails",1,"pd01er03"],"show": True},"pd01ed01": {"content": "6","path": ["accountInfos",1,"latest5year","latest5yearDetails",1,"pd01ed01"],"show": True}}]}
,"testy":["test"]
	}



@app.route('/getreport',methods =['post'])
def getreport():

    # print(type(request.get_data()))
    data = request.json.get('data')
    repo = data.get("repo")
    stra = data.get("stra").split('\n')
    print(repo)
    print(stra)
    res = DoJson().search_v(repo, stra)
    print(res)
    # print(repo)
    return res

@app.route('/update',methods =['post'])
def update():

    # print(type(request.get_data()))
    data = request.json.get('data')
    repo = json.loads(data.get("repo"))
    path = data.get("path")
    stra = data.get("stra")

    DoJson().set_v(repo,path,stra)
    print(repo)
    # print(repo)
    return repo


@app.route('/meun/')
def meun():
    dat = request.args.get("test")
    print(request.values.get("test"))
    print(dat)
    return jsonify(meun1)
# 4. 运行Flask应用， 可以指定ip和端口；

# '0.0.0.0' 所有的IP都可以访问到;

app.run('0.0.0.0', 9000)